/**
 * @file XFooterView.java
 * @create Mar 31, 2012 9:33:43 PM
 * @author Maxwin
 * @description XListView's footer
 */
package com.jy.app.lib.view.uilistview;


import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jy.app.lib.R;


public class UIListViewFooter extends LinearLayout {
	public final static int STATE_NORMAL = 0;
	public final static int STATE_READY = 1;
	public final static int STATE_LOADING = 2;
	public final static int STATE_COMPLETE = 3;
	
	
	private Context mContext;

	private View load_more_footer;
	private View loading_more_layout;
	private TextView load_text;
	private TextView load_complete;
	private String load_completeString = "";
	private String load_moreString = "";
	public UIListViewFooter(Context context) {
		super(context);
		initView(context);
	}
	
	public UIListViewFooter(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView(context);
	}

	
	public void setState(int state) {  
		if (state == STATE_READY) {
			loading_more_layout.setVisibility(View.VISIBLE);
			load_text.setText(R.string.xlistview_footer_hint_normal);
			load_complete.setVisibility(View.GONE);
		} else if (state == STATE_LOADING) {
			loading_more_layout.setVisibility(View.VISIBLE);
			load_text.setText(R.string.xlistview_header_hint_loading);
			load_complete.setVisibility(View.GONE);
		} else if (state == STATE_COMPLETE) {
			loading_more_layout.setVisibility(View.GONE); 
			load_complete.setText(load_completeString); 
			load_complete.setVisibility(View.VISIBLE);
		}else {
			load_complete.setText(load_moreString); 
			loading_more_layout.setVisibility(View.GONE); 
			load_complete.setVisibility(View.VISIBLE);
		}
	}
	
	public void setBottomMargin(int height) {
		if (height < 0) return ;
		LayoutParams lp = (LayoutParams)load_more_footer.getLayoutParams();
		lp.bottomMargin = height;
		load_more_footer.setLayoutParams(lp);
	}
	
	public int getBottomMargin() {
		LayoutParams lp = (LayoutParams)load_more_footer.getLayoutParams();
		return lp.bottomMargin;
	}
	
	/**
	 * normal status
	 */
/*	public void normal() {
		loading_more_layout.setVisibility(View.GONE); 
		load_complete.setVisibility(View.VISIBLE);
	}*/
	
	
	/**
	 * loading status 
	 */
	public void loading() {
		loading_more_layout.setVisibility(View.VISIBLE);
		load_text.setText(R.string.xlistview_header_hint_loading);
		load_complete.setVisibility(View.GONE);
 
	}
	
	/**
	 * hide footer when disable pull load more
	 */
	public void hide() {
/*		LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)load_more_footer.getLayoutParams();
		lp.height = 0;
		load_more_footer.setLayoutParams(lp);*/
		load_more_footer.setVisibility(View.INVISIBLE);
	}
	
	/**
	 * show footer
	 */
	public void show() {
/*		LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams)load_more_footer.getLayoutParams();
		lp.height = LayoutParams.WRAP_CONTENT;
		load_more_footer.setLayoutParams(lp);*/
		load_more_footer.setVisibility(View.VISIBLE);
	}
	
	private void initView(Context context) {
		mContext = context;
		
		RelativeLayout moreView = (RelativeLayout)LayoutInflater.from(mContext).inflate(R.layout.w_listview_load_more_footer, null);
		addView(moreView);
		moreView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
		
		load_more_footer = moreView.findViewById(R.id.load_more_footer);
		loading_more_layout = moreView.findViewById(R.id.loading_more_layout);
		load_text =  (TextView)moreView.findViewById(R.id.load_text);
		
		load_complete = (TextView)moreView.findViewById(R.id.load_complete);
		
		load_completeString = mContext.getResources().getString(R.string.xlistview_footer_hint_complete);
		load_moreString = mContext.getResources().getString(R.string.xlistview_footer_hint_normal);
		
	}
	
	
}
